package code.notdo;

import java.util.HashSet;
import java.util.Set;

/**
 * author : yeswater
 * date : 2023/12/16
 * 
 * 实现 trie (前缀树)
 * 
 */

public class T208 {
    Set<String> words;
    
    public T208() {
        words = new HashSet<>();
    }
    
    public void insert(String word) {
        words.add(word);
    }
    
    public boolean search(String word) {
        for (String t : words) {
            if (t.equals(word)) {
                return true;
            }
        }
        return false;
    }
    
    public boolean startsWith(String prefix) {
        for(String t : words) {
            if(t.startsWith(prefix)) {
                return true;
            }
        }
        return false;
    }
}
